#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
struct stu
{
	char name[20];
	int age;
	float score;
};
int main()
{
	struct stu s = { 0 };
	FILE* pf = fopen("file2.txt", "rb");
	if (pf == NULL)
	{
		perror("fopen");
		return 1;
	}
	fread(&s, sizeof(s), 1, pf);
	printf("%s %d %.1f\n", s.name, s.age, s.score);
	fclose(pf);
	pf = NULL;
	return 0;
}
int main5()
{
	struct stu s = { "zhangsan",20,95.5 };
	FILE* pf = fopen("file2.txt", "wb");
	if (pf == NULL)
	{
		perror("fopen");
		return 1;
	}
	fwrite(&s, sizeof(s), 1, pf);
	fclose(pf);
	pf = NULL;
	return 0;
}
int main4()
{
	struct stu s = { 0 };
	FILE* pf = fopen("file1.txt", "r");
	if (pf == NULL)
	{
		perror("fopen");
		return 1;
	}
	fscanf(pf, "%s %d %.1f", s.name, &(s.age), &(s.score));
	fprintf(stdout, "%s %d %.1f\n", s.name, s.age, s.score);
	fclose(pf);
	pf = NULL;
}
int main3()
{
	struct stu s = { "zhangsan",20,95.5 };
	FILE* pf = fopen("file1.txt", "w");
	if (pf == NULL)
	{
		perror("fopen");
		return 1;
	}
	fprintf(pf, "%s %d %.1f", s.name, s.age, s.score);
	fclose(pf);
	pf = NULL;
}
int main10()
{
	FILE* pf = fopen("file.txt", "w");
	if (pf == NULL)
	{
		perror("fopen");
		return 1;
	}
	fputs("haha", pf);
	fclose(pf);
	pf = NULL;

	FILE* pf1 = fopen("file.txt", "r");
	if (pf1 == NULL)
	{
		perror("fopen");
		return 1;
	}
	char str[20] = { 0 };
	fgets(str, 3, pf1);
	printf("%s\n", str);
	fclose(pf1);
	pf1 = NULL;
	return 0;
}
int main1()
{
	FILE* pf = fopen("hehe.txt", "w");
	if (pf == NULL)
	{
		perror("fopen");
		return 1;
	}
	fputc('A', pf);
	fputc('B', pf);
	fputc('C', pf);
	fclose(pf);
	pf = NULL;

	FILE* pf1 = fopen("hehe.txt", "r");
	if (pf1 == NULL)
	{
		perror("fopen");
		return 1;
	}
	int ch = fgetc(pf1);
	printf("%c\n", ch);
	ch = fgetc(pf1);
	printf("%c\n", ch);
	ch = fgetc(pf1);
	printf("%c\n", ch);
	fclose(pf1);
	pf1 = NULL;
	return 0;
}